<template>
  <div id="internetThings">
    <v-title title="测试复盘"></v-title>
    
    <v-condition :way="way"></v-condition>

    <v-content :way="way" :data="data"></v-content>
  </div>
</template>

<script>
  import VTitle from './title'
  import VCondition from './condition'
  import VContent from './content'
  import http from '@/views/sys/axios' 
  import { mapState } from 'vuex'

  export default {
    name: 'InternetThings',
    components: {
      VTitle,
      VCondition,
      VContent
    },
    computed: {
      ...mapState({
        condition: state => state.conditions.condition
      })     
    },
    beforeRouteEnter:(to,from,next)=>{
      next(vm => {
        if(to.path === '/sysconfig/internet-things/test-content') {
          vm.way = 'get'
        } else {
          vm.way = 'post'
        }
      })
    },
    data() {
      return {
        way: '',
        data: {}
      }
    },
    created() {
      if(this.condition.projectId) {
        this.getReplayResult()
      }
    },
    methods: {
      getReplay() {
        return http.get(`${process.env.VUE_APP_KANBAN_HOST}/api/data_summary/test_replay/entry?projectId=${this.condition.projectId}`)
      },
      async getReplayResult() {
        const { code, result } = await this.getReplay()
        try {
          if(code === 200) {
            this.data = result                                    
          }
        } catch(err) {
          console.log(err)
        }
      }
    },
    watch: {
      condition: {
        handler: function() {
          this.getReplayResult()
        },
        deep: true
      }
    }
  }
</script>

<style lang="scss" scoped>
  #internetThings {
    padding: 32px;
    background-color: rgb(240, 242, 245);
    position: relative;
    .btn{
      
    }
  }
</style>